<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>文件批量上传</title>
<link href="${CONTEXT_PATH}/common/batchUpload/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${CONTEXT_PATH}/common/batchUpload/js/swfupload.js"></script>
<script type="text/javascript" src="${CONTEXT_PATH}/common/batchUpload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="${CONTEXT_PATH}/common/batchUpload/js/fileprogress.js"></script>
<script type="text/javascript" src="${CONTEXT_PATH}/common/batchUpload/js/handlers.js"></script>
<script type="text/javascript">
		var swfu;
		var afterHandler = null;

		window.onload = function() {
			var action = '${CONTEXT_PATH}/<%=request.getParameter("action")%>';
			var maxSize = '<%=request.getParameter("maxSize")%>';
			var fileCount = <%=request.getParameter("fileCount")%>;
			var fileQueue = <%=request.getParameter("fileQueue")%>;
			var fileType = '<%=request.getParameter("fileType")%>';
			var size = ('null' == maxSize || '' == maxSize) ? '2MB' : maxSize;
			var count = ('null' == fileCount || '' == fileCount) ? 10 : parseInt(fileCount);
			var type = ('null' == fileType || '' == fileType) ? '*.*' : fileType;
			afterHandler = '<%=request.getParameter("afterUpload")%>' == '' ? null : '<%=request.getParameter("afterUpload")%>';
			initInfo(size, count, type);
			
			var settings = {
				flash_url : "${CONTEXT_PATH}/common/batchUpload/js/swfupload.swf",
				upload_url: action,
				post_params: {},
				file_size_limit : size,
				file_types : type,
				file_types_description : "All Files",
				file_upload_limit : count,
				file_queue_limit : fileQueue,
				file_post_name:"attachment",//对应action中的file
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,

				// Button settings
				button_image_url: "${CONTEXT_PATH}/common/batchUpload/images/TestImageNoText_65x29.png",
				button_width: "65",
				button_height: "29",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '<span class="theFont">浏览</span>',
				button_text_style: ".theFont { font-size: 16; }",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
				queue_complete_handler : eval(afterHandler)	// Queue plugin event
			};

			swfu = new SWFUpload(settings);
		};
	     
		function initInfo(s, c, t)
		{
			var sizeSpan = $('#sizeSpan');
			var countSpan = $('#countSpan');
			var typeSpan = $('#typeSpan');
			sizeSpan.text(s);
			countSpan.text(c);
			typeSpan.text(t);
		}
		
		function fileDialogComplete(numberselected, numberqueued) {
		     if (swfu.getStats().files_queued > 0) {
		    	 document.getElementById("btnCancel").disabled = false;
		     }
	     }

	     function upload() {
	    	if (swfu.getStats().files_queued > 0) {
	    		document.getElementById("btnCancel").disabled = true;
	    	 	swfu.startUpload();
	    	} else {
		    	//eval(afterHandler + '()');
	    	}
	     }
	</script>
</head>
<body>

<div id="content">
	<h2 class="sign">文件批量上传</h2>
	<form id="form1" action="" method="post" enctype="multipart/form-data">
		<p class="info">
			最大上传大小:&nbsp;<span id="sizeSpan"></span>
		</p>
		<p class="info">
			最大上传个数:&nbsp;<span id="countSpan"></span>
		</p>
		<p class="info">
			上传类型限制:&nbsp;<span id="typeSpan"></span>
		</p>
		<br />
		<div class="fieldset flash" id="fsUploadProgress">
			<span class="legend">上传进度</span>
		</div>
	 	<!--<div id="divStatus">0 Files Uploaded</div> -->
		<div>
			<span id="spanButtonPlaceHolder"></span>
			<input id="btnCancel" type="button" value="取消所有上传" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
		</div>
	</form>
</div>
</body>
</html>
